def deal_trigger(data):
    rt_price = data['rt_price']
    ave5 = data['ave5']
    ave10 = data['ave10']
    flag5 = data['flag5']
    flag10 = data['flag10']
    score_info = data['score_info']

    # 均线标志 ave_flag = 0  # 0:无动作 1:买入 -1 卖出
    if flag10 == 1 and rt_price > ave10:
        data['ave_flag'] = 1
    elif flag5 == 1 and rt_price > ave5:
        data['ave_flag'] = 1
    elif flag10 == -1 and rt_price < ave10:
        data['ave_flag'] = -1
    elif flag10 == -1 and rt_price < ave5:
        data['ave_flag'] = -1
    else:
        data['ave_flag'] = 0

    if 'macd_form' not in score_info.keys():
        return data
    macd_form = score_info['macd_form']
    # macd_flag = 0  # 0:无动作 1:买入 -1 卖出
    if macd_form == 'v':
        data['macd_flag'] = 1
    elif macd_form == '^':
        data['macd_flag'] = -1
    else:
        data['macd_flag'] = 0

    dif_form = score_info['dif_form']
    # dif_flag = 0  # 0:无动作 1:买入 -1 卖出
    if dif_form == 'v':
        data['dif_flag'] = 1
    elif dif_form == '^':
        data['dif_flag'] = -1
    else:
        data['dif_flag'] = 0

    macd_form2 = score_info['macd_form2']
    # macd_flag2 = 0  # 0:无动作 1:买入 -1 卖出
    if macd_form2 == '//':
        data['macd_flag2'] = 1
    elif macd_form2 == '\\':
        data['macd_flag2'] = -1
    else:
        data['macd_flag2'] = 0

    dea_form2 = score_info['dea_form2']
    # dea_flag2 = 0  # 0:无动作 1:买入 -1 卖出
    if dea_form2 == '//':
        data['dea_flag2'] = 1
    elif dea_form2 == '\\':
        data['dea_flag2'] = -1
    else:
        data['dea_flag2'] = 0

    dif_form2 = score_info['dif_form2']
    # dif_flag2 = 0  # 0:无动作 1:买入 -1 卖出
    if dif_form2 == '//':
        data['dif_flag2'] = 1
    elif dif_form2 == '\\':
        data['dif_flag2'] = -1
    else:
        data['dif_flag2'] = 0

    # 消息提示触发
    # (1) 突破十日线 and macd形态多头 全仓买入
    # (2) 跌破十日线 and macd形态空头 清仓卖出
    # (3) 突破5日均线,未突破10日均线,macd多头形态 半仓买入
    # (4) 跌破5日均线,未跌破10日线,macd空头形态 减半仓
    # 交易标志 deal_flag = 0  # 1:全仓 2:加半仓 3:清仓 4:减半仓
    if flag10 == 1 and rt_price > ave10 and (macd_form == '/' or macd_form == 'v'):
        data['deal_flag'] = 1
        data['result_file_path'] = '加仓'
        data['deal_price'] = rt_price
        data['trigger_time'] = data['deal_time']  # 触发时间
        data['flag5'] = -1  # 变更5日flag
        data['flag10'] = -1  # 变更10日flag
    elif flag5 == 1 and rt_price > ave5 and (macd_form == '/' or macd_form == 'v'):
        data['deal_flag'] = 2
        data['result_file_path'] = '入仓'
        data['deal_price'] = rt_price
        data['trigger_time'] = data['deal_time']
        data['flag5'] = -1  # 监控跌破
        data['flag10'] = 1  # 监控突破
    elif flag10 == -1 and rt_price < ave10 and (macd_form == '\\' or macd_form == '^'):
        data['deal_flag'] = 3
        data['result_file_path'] = '清仓'
        data['deal_price'] = rt_price
        data['trigger_time'] = data['deal_time']
        data['flag5'] = 1  # 变更5日flag
        data['flag10'] = 1  # 变更10日flag
    elif flag5 == -1 and rt_price < ave5 and (macd_form == '\\' or macd_form == '^'):
        data['deal_flag'] = 4
        data['result_file_path'] = '减仓'
        data['deal_price'] = rt_price
        data['trigger_time'] = data['deal_time']
        data['flag5'] = 1  # 监控突破
        data['flag10'] = -1  # 监控跌破
    else:
        data['deal_flag'] = 0

    return data


# 判断有没有拐点出现
def judge_flag(data):
    # 处理触发的情况
    # ave_flag = 0  # 0:无动作 1:买入 -1 卖出
    # macd_flag = 0  # 0:无动作 1:买入 -1 卖出
    # dif_flag = 0  # 0:无动作 1:买入 -1 卖出
    # macd_flag2 = 0  # 0:无动作 1:买入 -1 卖出
    # dea_flag2 = 0  # 0:无动作 1:买入 -1 卖出
    # dif_flag2 = 0  # 0:无动作 1:买入 -1 卖出
    ave_flag = data['ave_flag']
    macd_flag = data['macd_flag']
    dif_flag = data['dif_flag']
    macd_flag2 = data['macd_flag2']
    dea_flag2 = data['dea_flag2']
    dif_flag2 = data['dif_flag2']
    data['turn_form'] = str(ave_flag) + str(macd_flag) + str(dif_flag) \
                        + str(macd_flag2) + str(dea_flag2) + str(dif_flag2)
    if ave_flag != 0 or macd_flag != 0 or dif_flag != 0 or macd_flag2 != 0 or dea_flag2 != 0 or dif_flag2 != 0:
        return 1
    else:
        return 0


if __name__ == '__main__':
    deal_trigger({})
